package com.heima.wemedia.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.WemediaConstants;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class WemediaListener {

    @Autowired
    private WmUserService wmUserService;


    //监听审核通过
    @KafkaListener(topics = WemediaConstants.WM_USER_CREAT)
    public void onMessage(String message){
        ApUser apUser = JSON.parseObject(message, ApUser.class);
        WmUser wmUser=new WmUser();
        // 复制
        BeanUtils.copyProperties(apUser,wmUser);
        wmUser.setApUserId(apUser.getId());
        wmUser.setCreatedTime(new Date());
        wmUserService.save(wmUser);
    }
}
